<template>
  <div class="leftCont">
    <div class="leftTop">
      <img src="/img/logo_b.png" />
    </div>
    <div class="navCont">
      <div class="leftListCont">
        <div class="navItem" :key="index" v-for="(item, index) in leftArr">
          <div
            @click="navFn(item)"
            :class="item.active ? 'navTop_active' : 'navTop'"
          >
            <div :class="'iconfont ' + item.icon"></div>
            <div class="navItemVal">{{ item.val }}</div>
            <div
              :style="
                'transform: rotate(' + (item.active ? '180' : '0') + 'deg)'
              "
              class="openIcon el-icon-caret-bottom"
            ></div>
          </div>
          <div
            class="listCont"
            :style="
              'height: ' +
              (item.active ? item.childList.length * 50 + 'px' : '0px')
            "
          >
            <div
              @click="listFn(item2)"
              :class="
                $route.path.includes(item2.url) ? 'listItem_active' : 'listItem'
              "
              :key="index2"
              v-for="(item2, index2) in item.childList"
            >
              <div>{{ item2.val }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      leftArr: [
        {
          active: false,
          val: "系统首页",
          icon: "icon-shouye-lan",
          url: "home",
          childList: [{ val: "用户列表", url: "/homeUser" }],
        },
        {
          active: false,
          val: "充值中心",
          icon: "icon-icon-huichangchongzhijilu",
          url: "pay",
          childList: [{ val: "充值记录", url: "/payCenter" }],
        },
        {
          active: false,
          val: "简历中心",
          icon: "icon-jianli",
          url: "book",
          childList: [
            { val: "简历列表", url: "/bookList" },
            { val: "简历审核", url: "/bookExa" },
          ],
        },
        {
          active: false,
          val: "企业中心",
          icon: "icon-qiyerenzheng",
          url: "company",
          childList: [
            { val: "企业列表", url: "/companyList" },
            { val: "企业审核", url: "/companyExa" },
          ],
        },
        {
          active: false,
          val: "岗位中心",
          icon: "icon-gangwei",
          url: "work",
          childList: [
            { val: "岗位列表", url: "/workList" },
            { val: "岗位审核", url: "/workExa" },
          ],
        },
        {
          active: false,
          val: "需求中心",
          icon: "icon-a-xuqiu3",
          url: "need",
          childList: [
            { val: "需求列表", url: "/needList" },
            { val: "需求审核", url: "/needExa" },
          ],
        },
        {
          active: false,
          val: "账号中心",
          icon: "icon-zhanghao",
          url: "account",
          childList: [{ val: "虚拟账号", url: "/accountList" }],
        },
      ],
    };
  },
  props: {},
  methods: {
    listFn(item) {
      this.$router.push({ path: item.url });
    },
    navFn(item) {
      if (!item.active) {
        for (let i = 0; i < this.leftArr.length; i++) {
          this.leftArr[i].active = false;
        }
        item.active = true;
      } else {
        item.active = false;
      }
    },
    setLeft() {
      var url = this.$route.path;
      for (let i = 0; i < this.leftArr.length; i++) {
        if (url.includes(this.leftArr[i].url)) {
          this.leftArr[i].active = true;
        } else {
          this.leftArr[i].active = false;
        }
      }
    },
  },
  mounted() {},
  created() {
    this.setLeft();
  },
};
</script>

<style scoped lang="less">
.leftCont {
  width: 180px;
  height: 100%;
  padding: 30px 10px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  .leftTop {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      height: 100px;
    }
    .logoName {
      font-size: 18px;
      font-weight: bold;
      margin-left: 5px;
      color: rgb(70, 70, 70);
    }
  }
  .navCont {
    overflow-y: scroll;
    flex: 1;
    height: 10px;
    width: 100%;
    margin-top: 30px;
    .leftListCont {
      width: 100%;
      transition: all 0.3s linear;
      overflow: hidden;
      .navItem,
      .navItem2 {
        width: 100%;
        line-height: 50px;
        box-sizing: border-box;
        cursor: pointer;
        margin-bottom: 15px;
        transition: all 0.3s;
        .navTop,
        .navTop_active {
          display: flex;
          padding: 0 15px;
          box-sizing: border-box;
          align-items: center;
          background-color: #fff;
          color: #999;
          border-radius: 5px;
          justify-content: space-between;
          .openIcon {
            transition: all 0.3s linear;
          }
          .navItemVal {
            flex: 1;
            width: 10px;
          }
          .iconfont {
            margin-right: 15px;
            font-size: 20px;
          }
        }
        .navTop_active {
          background-color: #86a9fb;
          color: white;
        }
        .navTop:hover {
          background-color: #86a9fb;
          color: white;
        }
        .listCont {
          width: 100%;
          overflow: hidden;
          transition: all 0.3s linear;
          .listItem,
          .listItem_active {
            width: 100%;
            display: flex;
            /*border-radius: 5px;*/
            box-sizing: border-box;
            font-size: 14px;
            padding-left: 45px;
            background-color: #fff;
            color: #999;
            .iconfont {
              margin-right: 15px;
              font-size: 20px;
            }
          }
          .listItem_active {
            /*background-color: #86a9fb;*/
            color: #86a9fb;
          }
          .listItem:hover {
            color: #86a9fb;
            /*background-color: rgba(150,161,254,0.2);*/
          }
        }
      }
    }
  }
}
</style>
<style>
.navCont {
  overflow: -moz-scrollbars-none;
}
.navCont::-webkit-scrollbar {
  width: 0 !important;
}
.navCont {
  -ms-overflow-style: none;
}
</style>
